#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 15000;
int n,m,s,e;
int head[maxn],num_edge,d[maxn];
struct node{
	int next;
	int to;
	int dis;
}edge[maxn];

inline void read(int &x){
	char c;int f=1;
	while(!isdigit(c=getchar())){
		if(c=='-')f=-1;
	}
	x=c-'0';
	while(isdigit(c=getchar())){
		x=x*10+c-'0';
	}
	x=x*f;
}

void add_edge(int from,int to,int dis){
	num_edge++;
	edge[num_edge].next=head[from];
	edge[num_edge].to=to;
	edge[num_edge].dis=dis;
	head[from]=num_edge;
}

void spfa(){
	int inq[maxn];
	queue<int> q;
	for(int i=1;i<=n;i++)d[i]=666666666;
	d[s]=0;inq[s]=1;q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();inq[u]=1;
		for(int i=head[u];i!=0;i=edge[i].next){
			int v=edge[i].to;
			int w=edge[i].dis;
			if(d[v]>d[u]+w){
				d[v]=d[u]+w;
				q.push(v);
			}
		}
	}
}

int main(){
	read(n);
	read(m);
	read(s);
	read(e);
	int a,b,c;
	for(int i=1;i<=m;i++){
		read(a);read(b);read(c);
		add_edge(a,b,c);
		add_edge(b,a,c);
	}
	
	spfa();
	cout<<d[e]<<endl;
	return 0;
}
